package com.kc.business.service.impl;

import com.kc.business.domain.BizGoodsLease;
import com.kc.business.mapper.BizGoodsLeaseMapper;
import com.kc.business.service.IBizGoodsLeaseService;
import com.kc.common.utils.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 租赁商品管理service接口实现
 */
@Service
public class BizGoodsLeaseServiceImpl implements IBizGoodsLeaseService {
    @Resource
    private BizGoodsLeaseMapper bizGoodsLeaseMapper;
    /**
     * 商品添加
     * @param bizGoodsLease
     * @return
     */
    @Override
    public Integer add(BizGoodsLease bizGoodsLease) {
        if(bizGoodsLease.getStatus() == null){
            bizGoodsLease.setStatus(1);
        }
        return bizGoodsLeaseMapper.insert(bizGoodsLease);
    }
    /**
     * 商品编辑
     * @param bizGoodsLease
     * @return
     */
    @Override
    public Integer edit(BizGoodsLease bizGoodsLease) {
        if(bizGoodsLease.getStatus() == null){
            bizGoodsLease.setStatus(1);
        }
        return bizGoodsLeaseMapper.updateByPrimaryKey(bizGoodsLease);
    }
    /**
     * 商品列表
     * @return
     */
    @Override
    public List<BizGoodsLease> getList(BizGoodsLease bizGoodsLease) {
        List<BizGoodsLease> bizGoodsLeaseList = bizGoodsLeaseMapper.select(bizGoodsLease);
        bizGoodsLeaseList.forEach(goodsLease->{
            String[] list = StringUtils.split(goodsLease.getImages(),",");
            goodsLease.setGoodsImgs(list);
        });

        return bizGoodsLeaseList;
    }
    /**
     * 获取详情
     * @param bizGoodsLease
     * @return
     */
    @Override
    public BizGoodsLease getInfo(BizGoodsLease bizGoodsLease) {
        return bizGoodsLeaseMapper.selectOne(bizGoodsLease);
    }

    /**
     * 商品移除
     * @param bizGoodsLease
     * @return
     */
    @Override
    public Integer remove(BizGoodsLease bizGoodsLease) {
        return bizGoodsLeaseMapper.updateByPrimaryKey(bizGoodsLease);
    }
}
